using System;
using OpenEdge.Utility;

namespace OpenEdge.DatabaseEngineering.Generate
{
	public class Application : IDisposable
	{
		private OptionsForm			optionsForm;
		private DefinitionWriter	definitionWriter;
		private LogWriter			logWriter;
		private Generator			generator;

		public Application(EA.Repository repository)
		{

			optionsForm			= new OptionsForm();
			definitionWriter	= new DefinitionWriter();
			logWriter			= new LogWriter();
			generator			= new Generator(repository);

			optionsForm.OpenDefinitionWriter	+= new OptionsForm.OpenWriterRequest(this.definitionWriter.Open);
			optionsForm.OpenLogWriter			+= new OptionsForm.OpenWriterRequest(this.logWriter.Open);
			optionsForm.Generate				+= new OptionsForm.GenerateRequest(this.generator.generate);
			optionsForm.CloseDefinitionWriter	+= new OptionsForm.CloseWriterRequest(this.definitionWriter.Close);
			optionsForm.CloseLogWriter			+= new OpenEdge.DatabaseEngineering.Generate.OptionsForm.CloseWriterRequest(this.logWriter.Close);

			generator.initializeProgress        += new OpenEdge.DatabaseEngineering.Generate.Generator.ProgressEvent(this.optionsForm.ProgressBar1_Initialize);
			generator.updateProgress			+= new OpenEdge.DatabaseEngineering.Generate.Generator.ProgressEvent(this.optionsForm.ProgressBar1_Update);
			generator.generateComplete			+= new OpenEdge.DatabaseEngineering.Generate.Generator.CompleteEvent(this.definitionWriter.Generate_Complete);
			generator.generateComplete			+= new OpenEdge.DatabaseEngineering.Generate.Generator.CompleteEvent(this.optionsForm.Generate_Complete);

			generator.DefinitionWriteLine		+= new Generator.WriteRequest(this.definitionWriter.WriteLineHandler);
			generator.LogWriteLine				+= new Generator.WriteRequest(this.logWriter.WriteLineHandler);
			generator.LogWriteLine				+= new Generator.WriteRequest(this.optionsForm.logWriteLineHandler);

		}


		public void showOptionsForm() 
		{
			
			this.optionsForm.Show();

		}
		
		#region IDisposable Members

		public void Dispose()
		{
			// TODO:  Add Application.Dispose implementation
		}

		#endregion

	}
}
